set(CMAKE_SYSTEM_NAME Generic)

# which compilers to use for C and C++

# GCC编译器可选
#   riscv-none-embed-gcc
#   riscv32-esp-elf-gcc
#   riscv64-unknown-elf-gcc

set(CMAKE_C_COMPILER   riscv-none-embed-gcc)
set(CMAKE_CXX_COMPILER riscv-none-embed-g++)
set(CMAKE_OBJCOPY riscv-none-embed-objcopy)
set(CMAKE_GDB riscv-none-embed-gdb)

set(LINKER_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/misc/AgRV2K_FLASH.ld")
set(MAP_FILE    "ag32rv2k.map")

set(CMAKE_C_FLAGS "-march=rv32imac -ffunction-sections")
set(CMAKE_EXE_LINKER_FLAGS "-ffunction-sections -T ${LINKER_SCRIPT} -Xlinker --gc-sections -Wl,-Map,${MAP_FILE}  --specs=nano.specs --specs=nosys.specs")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-ffunction-sections -Xlinker --gc-sections --specs=nano.specs --specs=nosys.specs")

# where is the target environment located
# set(CMAKE_FIND_ROOT_PATH  /usr/i586-mingw32msvc
#     /home/alex/mingw-install)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)